<template>
    <div class="index-lists">
        <el-card class="!border-none mt-4" shadow="never">
            <div style="display: flex; justify-content: space-between">
                <el-button v-perms="['customertermrule:add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    添加规则
                </el-button>
                <el-form ref="formRef" :model="queryParams" :inline="true">
                    <el-form-item label="案件类型" style="" prop="caseType">
                        <el-select v-model="queryParams.caseType" clearable>
                            <el-option label="请选择字典生成" value="" />
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="ID" prop="id" min-width="50" />
                <el-table-column label="案件类型" prop="caseType" min-width="180" />
                <el-table-column label="处理事项" prop="handlingInformation" min-width="180" />
                <el-table-column label="案件阶段" prop="caseStage" min-width="180" />
                <el-table-column label="国家(地区)" prop="nation" min-width="180" />
                <el-table-column label="申请类型" prop="applicationType" min-width="180" />
                <el-table-column label="业务类型" prop="businessType" min-width="180" />
                <el-table-column label="内部基准日期" prop="interiorBaseDate" min-width="180" />
                <el-table-column
                    label="内部加减顺序"
                    prop="interiorAddSubtractOrder"
                    min-width="180"
                />
                <el-table-column
                    label="内部月数增量"
                    prop="interiorMonthlyIncrement"
                    min-width="180"
                />
                <el-table-column
                    label="内部天数增量"
                    prop="interiorDaysIncrement"
                    min-width="180"
                />
                <el-table-column label="客户基准日期" prop="customerBaseDate" min-width="180" />
                <el-table-column
                    label="客户加减顺序"
                    prop="customerAddSubtractOrder"
                    min-width="180"
                />
                <el-table-column
                    label="客户月数增量"
                    prop="customerMonthlyIncrement"
                    min-width="180"
                />
                <el-table-column
                    label="客户天数增量"
                    prop="customerDaysIncrement"
                    min-width="180"
                />
                <el-table-column label="官方基准日期" prop="officialBaseDate" min-width="180" />
                <el-table-column
                    label="官方加减顺序"
                    prop="officialAddSubtractOrder"
                    min-width="180"
                />
                <el-table-column
                    label="官方月数增量"
                    prop="officialMonthlyIncrement"
                    min-width="180"
                />
                <el-table-column
                    label="官方天数增量"
                    prop="officialDaysIncrement"
                    min-width="180"
                />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['customertermrule:edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            v-perms="['customertermrule:del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="customertermrule">
import { customertermruleDelete, customertermruleLists } from '@/api/customer/customerTermRule'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    caseTypeId: '',
    caseType: '',
    handlingInformation: '',
    caseStageId: '',
    caseStage: '',
    nation: '',
    applicationTypeId: '',
    applicationType: '',
    businessTypeId: '',
    businessType: '',
    interiorBaseDateStart: '',
    interiorBaseDateEnd: '',
    interiorAddSubtractOrder: '',
    interiorMonthlyIncrement: '',
    interiorDaysIncrement: '',
    customerBaseDateStart: '',
    customerBaseDateEnd: '',
    customerAddSubtractOrder: '',
    customerMonthlyIncrement: '',
    customerDaysIncrement: '',
    officialBaseDateStart: '',
    officialBaseDateEnd: '',
    officialAddSubtractOrder: '',
    officialMonthlyIncrement: '',
    officialDaysIncrement: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: customertermruleLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await customertermruleDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
